<template>
	<view class="page-wrap" :data-theme="theme" :class="theme" :style="globalColor.style">
		<HeadCustom linkId="usr18q86lsl0oe96" :isBack="isBack" :linkData="linkData"></HeadCustom>
		<view class="wrap">
			<EnterpriseHead ref="EnterpriseHead" :detail.sync="detail" @login="login" />
			<view class="line"></view>
			<DetailCollection ref="DetailCollection" :companyId="id" :menuCode="menuCode" />
			<template v-if="menuCode == 'COMPANY_OFFICIAL_WEBSITE'">
			<view class="fiexd-action">
				<view>
					<view class="action-item mt16 fboxCol Ycenter Xcenter" @click="$pageTo('/enterpriseQCode?id='+detail.companyId)">
						<text class="bwfont bw-erweima"></text>
						<view class="color-ACB4C7 font22 tit">二维码</view>
					</view>
					<view class="action-item mt16 fboxCol Ycenter Xcenter" @click="subCall('follow')">
						<text class="bwfont bw-guanzhu"></text>
						<view class="color-ACB4C7 font22 tit">{{detail.isFollow ? '已关注' : '关注'}}</view>
					</view>
					<view class="action-item mt16 fboxCol Ycenter Xcenter" @click="subCall('giveCard')">
						<text class="bwfont bw-mingpianxiangzi"></text>
						<view class="color-ACB4C7 font22 tit">名片箱</view>
					</view>
					<view class="action-item mt16 fboxCol Ycenter Xcenter" @click="subCall('callPhone')">
						<text class="bwfont bw-dianhua"></text>
						<view class="color-ACB4C7 font22 tit">电话</view>
					</view>
				</view>
				<!-- <view class="action-item mt16 fboxCol Ycenter Xcenter" @click="$pageTo('/about/guidePage')">
					<text class="bwfont bw-kefu color-E8CDA7"></text>
					<view class="color-ACB4C7 font22 tit">客服</view>
				</view> -->
			</view>
			</template>
			<template v-else>
				<!-- <DetailCollection ref="DetailCollection" :companyId="id" :menuCode="menuCode" /> -->
			</template>
		</view>
		<BottomTabbar :company="detail" :userId="id" :active.sync="menuCode" type="enterprise" />
		<not-login ref="notLogin" bottom='160rpx' />
	</view>
</template>

<script>
	import { companyCardPreview, followCompanyRemove, followCompany, bestowCompany } from '@/api/card.js';
	import { completeInformation } from '@/api/mine.js';
	import BottomTabbar from '@/components/bottom-btn/bottom-tabbar.vue'
	import EnterpriseHead from '../components/enterprise-head.vue'
	import DetailCollection from '../components/detail-collection.vue';
	export default {
		components: {BottomTabbar, DetailCollection, EnterpriseHead},
		data() {
			return {
				theme: getApp().globalData.appTheme,
						globalColor: getApp().globalData.globalColor,
				detail:{},
				menuCode: '',
				id: '',
				scrollTop: 0,
				isModal: false,
				linkData: {id:''},
				isScan: true,
				isBack: true
			}
		},
		onLoad(options) {
			if(options && options.id){
				this.id = options.id
				this.linkData= {id:options.id}
			}
			if(options && options.isScan){
				this.isScan =  false
			}else{
				this.isScan =  true
			}
			if(options && options.menuCode){
				this.menuCode = options.menuCode
			}
			if(options.scene){
				// 扫码进入页面传递参数
				var scene = decodeURIComponent(options.scene); 
				var obj = {};
				for (var i = 0; i < scene.split('*').length;i++){
				  var arr = scene.split('*')[i].split('/');
				  obj[arr[0]] = arr[1];
				}
				this.id = obj.id
			}
			if(options && options.isBack){
				this.isBack = false
			}
		},
		onShow() {
			this.getInit()
		},
		methods: {
			// 弹出登录
			login(){
				this.$refs.notLogin.openLogin({
					show: true,
					position: 'center'
				})
			},
			getInit() {
				companyCardPreview({companyId: this.id}).then(res=>{
					this.detail = res.data
					this.menuCode = this.menuCode ? this.menuCode : res.data.list[0].menuCode
					uni.setNavigationBarTitle({
						title: `${res.data.companyName}-企业名片`
					})
					setTimeout(()=>{
						if(!res.data.isGive && this.isScan){
							this.$refs.EnterpriseHead.isModal = true
						}
					}, 5000)
				})
			},
			// 回调组件方法
			subCall(type){
				if(type == 'callPhone'){
					this.$refs.EnterpriseHead.callPhone()
				}
				if(type == 'giveCard'){
					this.$refs.EnterpriseHead.isModal = true
				}
				if(type == 'follow'){
					this.$refs.EnterpriseHead.follow()
				}
			}
		},
		onPageScroll(val) {
			this.scrollTop = val.scrollTop
		},
		onReachBottom() {
			// console.log('onReachBottom')
			if(this.$refs.DetailCollection){
				this.$refs.DetailCollection.listMore()
			}
		}
	}
</script>

<style lang="scss" scoped>
	.fiexd-action{position: fixed;right: 40rpx;bottom: 300rpx;z-index: 99;}
	.fiexd-action .action-item{width: 98rpx;height: 98rpx;background:var(--darkViewBgColor);border-radius: 50%;}
	.fiexd-action .action-item .bwfont{font-size: 28rpx;color: var(--buttonOutlineOneColor);}
	.fiexd-action .action-item .tit{ margin-top: 8rpx; line-height: 28rpx;}
	

	.line {
		margin: 0 auto;
		width: 670rpx;
		height: 1rpx;
		background: var(--backgroundDivisionColor);
	}
</style>